﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static Dictionary<int,Student> student = new Dictionary<int, Student>();
        static void Main(string[] args)
        {
            Student s = new Student(5,"张三",18);
            Student s1 = new Student(7,"李四",20);
            student.Add(s.StuNum,s);
            student.Add(s1.StuNum,s1);
            MessAge();
        }

        private static void MessAge()
        {
            while (true)
            {
                Console.WriteLine("请选择：1、添加学生信息。2、删除学生信息 2、查询学生信息。");
                int key = int.Parse(Console.ReadLine());
                switch (key)
                {
                    case 1:

                        AddStudent();
                        break;
                    case 2:
                        DeletStudent();
                        break;
                    case 3:
                        QueryStudent();
                        break;
                    default:
                        break;
                }
            }
        }

        private static void QueryStudent()
        {
            while (true)
            {
                Console.WriteLine("查询学生信息功能中有：1、查询所有（按学号排序）2、查询所有（按姓名排序），2、查询所有（按年龄排序）4、按学号查询（查没有，则打印查无此学生）5、退出");
                int key = int.Parse(Console.ReadLine());
                switch (key)
                {
                    case 1:
                        List<Student> stunum = student.Values.ToList();
                        stunum.Sort(new StuNum());
                        Prlis(stunum);
                        MessAge();
                        break;
                    case 2:
                        List<Student> stuname = student.Values.ToList();
                        stuname.Sort(new StuName());
                        Prlis(stuname);
                        MessAge();
                        break;
                    case 3:
                        List<Student> stuage = student.Values.ToList();
                        stuage.Sort(new StuNum());
                        Prlis(stuage);
                        MessAge();
                        break;
                    case 4:
                        Console.WriteLine("请输入学号");
                        int keys = int.Parse(Console.ReadLine());
                        if (student.ContainsKey(keys))
                        {
                            Console.WriteLine(student[keys]);
                        }
                        else
                        {
                            Console.WriteLine("查无此学生");
                        }
                        MessAge();
                        break;
                    case 5:
                        break;
                    default:
                        break;
                }
            }
        }

        private static void Prlis(List<Student> student)
        {
            foreach (var item in student)
            {
                Console.WriteLine(item);
            }
        }

        private static void DeletStudent()
        {
            student.Remove(5);
            Console.WriteLine("删除成功");
            
        }

        private static void AddStudent()
        {
            Student s = new Student();
            Console.WriteLine("请输入学号");
            s.StuNum = int.Parse(Console.ReadLine());
            Console.WriteLine("请输入姓名");
            s.Name = Console.ReadLine();
            Console.WriteLine("请输入年龄");
            s.Age = int.Parse(Console.ReadLine());
            if (student.ContainsKey(s.StuNum))
            {
                Console.WriteLine("学号已存在，请重新输入");
            }
            else
            {
                student[s.StuNum] = s;
            }
            MessAge();
        }
    }
}
